"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const redux_1 = require("@tarojs/redux");
const taro_1 = require("@tarojs/taro");
const components_1 = require("@tarojs/components");
const taro_ui_1 = require("taro-ui");
const feedbacks_1 = require("../../actions/feedbacks");
require("./Feedbacks.scss");
let FeedBacks = class FeedBacks extends taro_1.Component {
    constructor() {
        super(...arguments);
        this.config = {
            navigationBarTitleText: '意见反馈'
        };
        this.state = {
            data: {
                content: ''
            },
            disabled: false,
            isToastOpened: false,
            toastTips: '内容不能为空！'
        };
        this.handleTextareaChange = e => {
            this.setState(state => (Object.assign({}, state, { data: Object.assign({}, state.data, { content: e.target.value }) })));
        };
        this.handleSubmit = () => {
            if (String(this.state.data.content).trim() === '') {
                this.setState(state => (Object.assign({}, state, { isToastOpened: true })));
            }
            else {
                this.props.add(this.state.data, data => {
                    if (data.errno) {
                        this.setState(state => (Object.assign({}, state, { isToastOpened: true, toastTips: '意见反馈提交失败' })));
                    }
                    else {
                        this.setState(state => (Object.assign({}, state, { disabled: true, isToastOpened: true, toastTips: '意见反馈提交成功' })));
                    }
                    console.log(data, 'callback');
                });
            }
        };
    }
    componentDidMount() {
    }
    render() {
        return (<components_1.View className='feedback'>
              <taro_ui_1.AtToast isOpened={this.state.isToastOpened} text={this.state.toastTips}/>
              <taro_ui_1.AtTextarea value={this.state.data.content} onChange={this.handleTextareaChange} maxlength='200' placeholder='请输入您对我们的意见或建议'/>
              <components_1.View className='buttonFix'>
                <taro_ui_1.AtButton className='btn' type='primary' onClick={this.handleSubmit} disabled={this.state.disabled}>提交</taro_ui_1.AtButton>
              </components_1.View>
            </components_1.View>);
    }
};
FeedBacks = __decorate([
    redux_1.connect(({ feedbacks }) => ({
        feedbacks
    }), (dispatch) => ({
        add(data, callback) {
            dispatch(feedbacks_1.add(data, callback));
        }
    }))
], FeedBacks);
exports.default = FeedBacks;
//# sourceMappingURL=Feedbacks.jsx.map